
var HUD = function(stage, canvasWidth, game){
    var _game = game;
    var txt = new createjs.Text("0", "30px Verdana", "white");
    txt.textAlign = "center";
    txt.x = canvasWidth/2;
    txt.y = 0;
    stage.addChild(txt);
    
    var researchPoint = new createjs.Text("100%", "30px Verdana", "#99aaff");
    researchPoint.x = 62;
    researchPoint.y = 5;
    stage.addChild(researchPoint);
    
    var spellFreeze = new SpellFreeze();
    var spellAddPVResearchCenter = new SpellAddPVResearchCenter();
    var spellAddPVPacket = new SpellAddPVPacket();
    var spellKnowledgeColourless = new SpellKnowledgeColourless();
    
    
    var spellFreezeButton = new createjs.Shape();
    var _imageSpellFreeze;
    _imageSpellFreeze = ImageEngine.getInstance().getSpellFreeze();
    spellFreezeButton.graphics.beginBitmapFill(_imageSpellFreeze).drawRoundRect(0, 0, 42, 42,0);
    spellFreezeButton.x = 10;
    spellFreezeButton.y = 10;
    spellFreezeButton.onClick = function(evt){
        game.addSpellToWaitingList(spellFreeze);
    };
    stage.addChild(spellFreezeButton);
    
    var spellAddPVResearchCenterButton = new createjs.Shape();
    var _imageSpellAddPVResearchCenter;
    _imageSpellAddPVResearchCenter = ImageEngine.getInstance().getSpellAddResearchCenterPV();
    spellAddPVResearchCenterButton.graphics.beginBitmapFill(_imageSpellAddPVResearchCenter).drawRoundRect(0, 0, 42, 42,0);
    spellAddPVResearchCenterButton.x = 10;
    spellAddPVResearchCenterButton.y = 62;
    spellAddPVResearchCenterButton.onClick = function(evt){
        game.addSpellToWaitingList(spellAddPVResearchCenter);
    };
    stage.addChild(spellAddPVResearchCenterButton);
    
    var spellAddPVPacketButton = new createjs.Shape();
    var _imageSpellAddPVPacket;
    _imageSpellAddPVPacket = ImageEngine.getInstance().getSpellAddKnowledgePV();
    spellAddPVPacketButton.graphics.beginBitmapFill(_imageSpellAddPVPacket).drawRoundRect(0, 0, 42, 42,0);
    spellAddPVPacketButton.x = 10;
    spellAddPVPacketButton.y = 114;
    spellAddPVPacketButton.onClick = function(evt){
        game.addSpellToWaitingList(spellAddPVPacket);
    };
    stage.addChild(spellAddPVPacketButton);
    
    var spellKnowledgeColourlessButton = new createjs.Shape();
    var _imageSpellKnowledgeColourless;
    _imageSpellKnowledgeColourless = ImageEngine.getInstance().getSpellKnowledgeColorless();
    spellKnowledgeColourlessButton.graphics.beginBitmapFill(_imageSpellKnowledgeColourless).drawRoundRect(0, 0, 42, 42,0);
    spellKnowledgeColourlessButton.x = 10;
    spellKnowledgeColourlessButton.y = 166;
    spellKnowledgeColourlessButton.onClick = function(evt){
        game.addSpellToWaitingList(spellKnowledgeColourless);
    };
    stage.addChild(spellKnowledgeColourlessButton);
    
    var pauseButton = new createjs.Shape();
    var _imagePause;
    _imagePause = ImageEngine.getInstance().getPause();
    pauseButton.graphics.beginBitmapFill(_imagePause).drawRoundRect(0, 0, 42, 42,0);
    //pauseButton.graphics.beginFill("black").drawRoundRect(0, 0, 42, 42,0);
    pauseButton.x = canvasWidth - 200;
    pauseButton.y = 5;
    pauseButton.onClick = function(evt){
        game.togglePause();
    };
    stage.addChild(pauseButton);
    
    var muteFXButton = new createjs.Shape();
    var _imageMuteFXButton = ImageEngine.getInstance().getFxMute();
    muteFXButton.graphics.beginBitmapFill(_imageMuteFXButton).drawRoundRect(0, 0, 42, 42,0);
    //muteFXButton.graphics.beginFill("white").drawRoundRect(0, 0, 42, 42,0);
    muteFXButton.x = canvasWidth - 250;
    muteFXButton.y = 5;
    muteFXButton.onClick = function(evt){
        SoundEngine.getInstance().toggleFx();
    };
    stage.addChild(muteFXButton);
    
    var muteMusicButton = new createjs.Shape();
    var _imageMuteMusicButton = ImageEngine.getInstance().getMusicMute();
    muteMusicButton.graphics.beginBitmapFill(_imageMuteMusicButton).drawRoundRect(0, 0, 42, 42,0);
    //muteMusicButton.graphics.beginFill("blue").drawRoundRect(0, 0, 42, 42,0);
    muteMusicButton.x = canvasWidth - 300;
    muteMusicButton.y = 5;
    muteMusicButton.onClick = function(evt){
        SoundEngine.getInstance().toggleMusic();
    };
    stage.addChild(muteMusicButton);
    
    
    
    this.updateWithScoreAndMana = function(score, mana){
        if(mana < spellFreeze.costInMana()){
            spellFreezeButton.visible = false;
        } else {
            spellFreezeButton.visible = true;
        }
        if(mana < spellAddPVResearchCenter.costInMana()){
            spellAddPVResearchCenterButton.visible = false;
        } else {
            spellAddPVResearchCenterButton.visible = true;
        }
        
        if(mana < spellAddPVPacket.costInMana()){
            spellAddPVPacketButton.visible = false;
        } else {
            spellAddPVPacketButton.visible = true;
        }
        
        if(mana < spellKnowledgeColourless.costInMana()){
            spellKnowledgeColourlessButton.visible = false;
        } else {
            spellKnowledgeColourlessButton.visible = true;
        }
        researchPoint.text = mana;
        txt.text = score;
    };
    
}